package com.ouc.eddyAlgorithm.controller;


import com.ouc.common.config.properties.ApplicationProperties;
import com.ouc.eddyAlgorithm.domain.OUCAjaxResult;
import com.ouc.eddyAlgorithm.service.EddyProfileService;
import com.ouc.visualization.entity.FactorCondition;
import org.springframework.beans.factory.annotation.Autowired;
import ucar.nc2.NetcdfFile;
import org.springframework.web.bind.annotation.*;

/**
 * @author B504
 */
@RestController
@RequestMapping("/profile")
@CrossOrigin
public class ProfilesController {

  @Autowired
  private ApplicationProperties appPro;

  @Autowired
  private EddyProfileService eddyProfileService;

  @GetMapping("profileData")
  public OUCAjaxResult profileData(@RequestParam("filePath") String filePath,
                                   FactorCondition factorCondition) {
    try {
      NetcdfFile ncFile = NetcdfFile.open(filePath);
      return OUCAjaxResult.ok(eddyProfileService.getProfileData(ncFile, factorCondition.getVariableName(),
          new Float[]{factorCondition.getStartLon(), factorCondition.getEndLon()}, new Float[]{factorCondition.getStartLat(), factorCondition.getEndLat()}, null));
    } catch (Exception e) {
      e.printStackTrace();
      return OUCAjaxResult.error("文件解析错误，请检查参数是否有误！！！");
    }
  }

}
